﻿import com.gamepackage.events.Executable;
import com.gamepackage.events.Call;
import com.gamepackage.events.Impuls;

class com.gamepackage.events.Interval
{
	private var exe: Executable;
	private var length: Number;

	private var frame: Number;

	private var checkCall: Call;

	function Interval( exe: Executable, length )
	{
		this.exe = exe;
		this.length = length;

		frame = 0;

		Impuls.connect( checkCall = new Call( this , this.check ) );
	}

	function clear(): Void
	{
		Impuls.disconnect( checkCall );
	}

	private function check(): Void
	{
		if ( ++frame % length == 0 )
		{
			exe.execute();
		}
	}
}